package org.magento.pages;



import org.magento.data.DefaultProduct;
import org.magento.utils.ConfigProperties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

// This class presents index  page (main FE) 
public class HomePage extends Page {
	
	//Locators 
	@FindBy(linkText = "Log In")
	public WebElement logIn;
	
	@FindBy(id = "search")
	public WebElement searchField;
	
	@FindBy(xpath = "/descendant::div[@class='form-search']/button")
	public WebElement searchButton;
	
	//Actions 
	public LoginPageFrontEnd gotoLoginPage() {
		logIn.click();
		return PageFactory.initElements(driver, LoginPageFrontEnd.class);
	}
	
	public SearchResult findDefaultProduct(DefaultProduct defaultProduct) {
		type(searchField, defaultProduct.name);
		searchButton.click();
		return PageFactory.initElements(driver, SearchResult.class);
	}
	
	// Assertions: 
	public boolean isHomepageDisplayed () {
		return driver.findElement(By.cssSelector("BODY")).getText().contains("Home Page");
	}
    
	
	//Auto - generated  
	public HomePage(WebDriver driver) {
		super(driver);
	}

	@Override
	public void open() {
		driver.get(ConfigProperties.getProperty("url.home"));	
	}

}
